﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using DataEditor.Components;

namespace DataEditor.BuisnessLayer
{
    public class UIBuilder
    {
        public static Expander FormExpanderFromOccupation(OccupationsOccupation pData,bool isExpanded){

            var stpnl = new StackPanel();

            foreach (var skill in pData.Skills)
                stpnl.Children.Add(new SkillInList(skill));

            //add emty skill to add possobility to create new(edit empty)
            var emptySkill = new OccupationsOccupationSkill
            {
                AccessLvl ="0",
                Name = "Select name",
                Type = OccupationsOccupationSkillType.Passive,
                Description = "Double click to change description",
                SkillIcon = ""
            };
            if (!ExistsInList(pData.Skills,emptySkill))
            { 
                pData.Skills.Add(emptySkill);
                stpnl.Children.Add(new SkillInList(emptySkill));
            }

            var expander = new Expander{
                Header = pData.Name,
                Content =stpnl,
                IsExpanded = isExpanded
            };

            return expander;
        }

        private static bool ExistsInList(List<OccupationsOccupationSkill> pSkillList, OccupationsOccupationSkill pSkill) 
        {
            foreach (var skill in pSkillList)
                if (skill.AccessLvl.Equals(pSkill.AccessLvl) &&
                       skill.Description.Equals(pSkill.Description) &&
                       skill.Name.Equals(pSkill.Name) &&
                       skill.SkillIcon.Equals(pSkill.SkillIcon))
                    return true;
            return false;
        }
    }
}
